# Contributor: Ruven Pillay <ruven@users.sourceforge.net>
# Maintainer: Ruven Pillay <ruven@users.sourceforge.net>
pkgname=iipsrv
pkgver=1.2
pkgrel=0
pkgdesc="IIPImage image server: iipsrv. An advanced high-performance image server for high-resolution and scientific images"
url="https://iipimage.sourceforge.io"
arch="all"
options="!check" # No test suite
license="GPL-3.0-or-later"
makedepends="tiff-dev fcgi-dev libjpeg-turbo-dev zlib-dev libmemcached-dev openjpeg-dev libpng-dev libwebp-dev"
install="$pkgname.pre-install"
source="https://downloads.sourceforge.net/iipimage/IIP%20Server/iipsrv-$pkgver/iipsrv-$pkgver.tar.bz2
	lighttpd.iipsrv.conf
	apache.iipsrv.conf
	iipsrv.initd
	iipsrv.confd
	RawTile.patch"
subpackages="$pkgname-doc $pkgname-openrc $pkgname-lighttpd:lighttpd:noarch $pkgname-apache:apache:noarch"

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var
	make
}

package() {
	make DESTDIR="$pkgdir" install
	# Rename our binary to just iipsrv and copy to /usr/bin
	mv src/iipsrv.fcgi src/iipsrv
	install -D -t $pkgdir/usr/bin/ src/iipsrv
	# Remove FCGI includes
	rm -fr $pkgdir/usr/include
	# Add OpenRC files
	install -Dm644 $srcdir/iipsrv.confd $pkgdir/etc/conf.d/iipsrv
	install -Dm755 $srcdir/iipsrv.initd $pkgdir/etc/init.d/iipsrv
}

lighttpd() {
	pkgdesc="Configuration file for Lighttpd"
	install_if="$pkgname=$pkgver-r$pkgrel lighttpd"
	install -Dm644 lighttpd.iipsrv.conf $subpkgdir/etc/lighttpd/iipsrv.conf
}

apache() {
	pkgdesc="Configuration file for Apache"
	install_if="$pkgname=$pkgver-r$pkgrel apache2-proxy"
	install -Dm644 apache.iipsrv.conf $subpkgdir/etc/apache2/conf.d/iipsrv.conf
}

sha512sums="
76d7dee476384e24dc13c8e37ed14999c8c584742303456cbc893eb11b2e5e6effe01f208f84830cefb48694290252908826550bf89d0fb1a8c6c82f1bc30fcd  iipsrv-1.2.tar.bz2
244c16de76c2c13975c7e48db61a9d957833c424f4060f2b762fc6984323339bc0a8fec27ebdbfa25677969e5ee49bde4c2aec11a57c7b25a73689f23d983ffc  lighttpd.iipsrv.conf
905c5c921bb1521963196a60e4cc2059a92fc197e7b37dfb19efeda35213d19721b790b7dc373d71f355329a4eb56d46a7a96e9e7dd52ee30001d4255dcb91a2  apache.iipsrv.conf
035be8c8c10aa01531027c0ff05d0d2402812ac2bf066d247044a2f023581b3f1cd533532153a66fce67f0a819769639607542dc78e8de78e11b3da4bb7d7fc8  iipsrv.initd
db17270cac0d142d0b187900415e5927269e0dc6f5d145b545c9855006ecd77cee4816ebeff7b1d9313abb4da9c07ec423c6eb4a7b63e07030a71589e48e330b  iipsrv.confd
6ff8e9b10ea7c3cb97a9570326d2538ea1f14bde41e2be5657d21e048e20ebf2e5d7cf7898dea8a29b6a420807c29af1549417fd217a2655f633e83c8c849509  RawTile.patch
"
